import { defineStore } from 'pinia'

export type MsgType = 'info' | 'success' | 'error'
export interface Msg { id: number; type: MsgType; text: string }

export const useUiStore = defineStore('ui', {
  state: () => ({ messages: [] as Msg[] }),
  actions: {
    push(type: MsgType, text: string) {
      const id = Date.now() + Math.random()
      this.messages.push({ id, type, text })
      setTimeout(() => this.remove(id), 3000)
    },
    remove(id: number) {
      this.messages = this.messages.filter(m => m.id !== id)
    }
  }
})